﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SisGrafeno;
using SisGrafenoController;

namespace SisGrafenoApp
{
    public partial class ReporteForm : Form
    {
        public ReporteForm()
        {
            InitializeComponent();
        }

        private void ReporteForm_Load(object sender, EventArgs e)
        {

        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            List<Cotizacion> list = new List<Cotizacion>();

            DateTime start = dtStart.Value;
            DateTime end = dtEnd.Value;

            list = MainController.getCotizacionByDateRange(start,end);

            System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\SISTEMAS 2 - IMPLEMENTACIÓN\\SisGrafeno\\ReporteCotizaciones.html");
            file.WriteLine("<html>");
                file.WriteLine("<head>");
                    file.WriteLine("<meta charset=\"UTF-8\">");
                    file.WriteLine("<title>");
                        file.WriteLine("Reporte de Cotizaciones");
                    file.WriteLine("</title>");
                file.WriteLine("</head>");
                file.WriteLine("<body>");
                    file.WriteLine("<h1 style=\"text-align: center;\">");
                    file.WriteLine("Reporte de Cotizaciones");
                    file.WriteLine("</h1>");
                    file.WriteLine("<h2 style=\"text-align: center;\">");
                    file.WriteLine("Emitidas del " + dtStart.Text + " al " + dtEnd.Text);
                    file.WriteLine("</h2>");
                    file.WriteLine("<h3 style=\"text-align: left;\">");
                    file.WriteLine("Fecha del Reporte: " + DateTime.Now);
                    file.WriteLine("</h3>");

                    //Tabla
                    file.WriteLine("<table border=\"1\" style =\"width:100%\">");
                    file.WriteLine("<tr>");
                    file.WriteLine("<td>");
                    file.WriteLine("Orden");
                    file.WriteLine("</td>");

                    file.WriteLine("<td>");
                    file.WriteLine("Codigo");
                    file.WriteLine("</td>");

                    file.WriteLine("<td>");
                    file.WriteLine("Fecha");
                    file.WriteLine("</td>");

                    file.WriteLine("<td>");
                    file.WriteLine("Cliente");
                    file.WriteLine("</td>");

                    file.WriteLine("<td>");
                    file.WriteLine("Estado");
                    file.WriteLine("</td>");

                    file.WriteLine("<td>");
                    file.WriteLine("Monto Total");
                    file.WriteLine("</td>");

                    file.WriteLine("</tr>");
                    for (int i = 0; i < list.Count; i++)
                    {
                        file.WriteLine("<tr>");
                        file.WriteLine("<td>");
                        file.WriteLine("" + i);
                        file.WriteLine("</td>");

                        file.WriteLine("<td>");
                        file.WriteLine("" + list[i].getId());
                        file.WriteLine("</td>");

                        file.WriteLine("<td>");
                        file.WriteLine("" + list[i].getFecha());
                        file.WriteLine("</td>");

                        file.WriteLine("<td>");
                        file.WriteLine("" + list[i].getCliente().getNombres() + " " + list[i].getCliente().getApellidos());
                        file.WriteLine("</td>");

                        file.WriteLine("<td>");
                        file.WriteLine(list[i].getEstado());
                        file.WriteLine("</td>");

                        file.WriteLine("<td>");
                        file.WriteLine("" + list[i].getMontoTotal());
                        file.WriteLine("</td>");

                        file.WriteLine("</tr>");
                    }
                    file.WriteLine("</table>");
                file.WriteLine("</body>");
            file.WriteLine("</html>");
            file.Close();
            MessageBox.Show("Reporte creado!",
                    "Resultado",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button1);
        }
    }
}
